/**
 * 0707
 *  
 * @Author : roryrywang
 * @DateTime : 2024/8/13 22:07
 */

#include <iostream>
#include <vector>

using namespace std;

struct DoubleListNode {
    int val;
    DoubleListNode *pre;
    DoubleListNode *next;

    DoubleListNode() : val(0), pre(nullptr), next(nullptr) {}

    DoubleListNode(int x) : val(x), pre(nullptr), next(nullptr) {}

    DoubleListNode(int x, DoubleListNode *pre, DoubleListNode *next) : val(x), pre(pre), next(next) {}
};

class MyLinkedList {
private:
    DoubleListNode *head;
    DoubleListNode *tail;
    int cnt;
public:
    MyLinkedList() {
        cnt = 0;
        head = new DoubleListNode(-1);
        tail = new DoubleListNode(-1);
        head->next = tail;
        tail->pre = head;
    }

    int get(int index) {
        if (index >= cnt) return -1;
        DoubleListNode *p = head->next;
        for (int i = 0; i < index; ++i) {
            p = p->next;
        }
        return p->val;
    }

    void addAtHead(int val) {
        DoubleListNode *p = new DoubleListNode(val);
        p->next = head->next;
        p->pre = head;
        p->next->pre = p;
        head->next = p;
        cnt++;
    }

    void addAtTail(int val) {
        DoubleListNode *p = new DoubleListNode(val);
        p->pre = tail->pre;
        p->next = tail;
        p->pre->next = p;
        tail->pre = p;
        cnt++;
    }

    void addAtIndex(int index, int val) {
        if (index > cnt)return;
        DoubleListNode *p = head->next;
        for (int i = 0; i < index; ++i) {
            p = p->next;
        }
        DoubleListNode *s = new DoubleListNode(val);
        s->next = p;
        s->pre = p->pre;
        s->pre->next = s;
        s->next->pre = s;
        cnt++;
    }

    void deleteAtIndex(int index) {
        if (index >= cnt)return;
        DoubleListNode *p = head;
        for (int i = 0; i < index; ++i) {
            p = p->next;
        }
        DoubleListNode *tmp = p->next;
        p->next = p->next->next;
        p->next->pre = p;
        delete tmp;
        cnt--;
    }
};

int main() {

    return 0;
}